package com.vito.dcs.modify.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.vito.base.factory.IDFactory;
import com.vito.dcs.modify.dao.DataModifyMapper;
import com.vito.dcs.modify.model.DataModifyModel;
import com.vito.dcs.modify.service.DataModifyService;

@Service
public class DataModifyServiceImpl implements DataModifyService{

	@Autowired
	private DataModifyMapper dataModifyMapper;
	
	@Override
	public void saveDataModify(DataModifyModel dataModifyModel) {
		dataModifyMapper.deleteDataModify(dataModifyModel);
		String id = IDFactory.getIDFactory().getIdInc("tbl_dcs_data_modify") + "";
		dataModifyModel.setId(id);
		dataModifyMapper.saveDataModify(dataModifyModel);
	}

	@Override
	public void deleteDataModify(DataModifyModel dataModifyModel) {
		dataModifyMapper.deleteDataModify(dataModifyModel);
	}

	@Override
	public DataModifyModel queryDataModifyBySectionId(
			DataModifyModel dataModifyModel) {
		return dataModifyMapper.queryDataModifyBySectionId(dataModifyModel);
	}

	@Override
	public boolean queryIsLegal(DataModifyModel dataModifyModel) {
		
		DataModifyModel queryAsphaltPlannedBySectionId = dataModifyMapper.queryAsphaltPlannedBySectionId(dataModifyModel);
		DataModifyModel queryWaterPlannedBySectionId = dataModifyMapper.queryWaterPlannedBySectionId(dataModifyModel);
		
		if(dataModifyModel.getAsphaltValue() > queryAsphaltPlannedBySectionId.getPlannedTotalAsphalt()
				|| dataModifyModel.getWaterValue() > queryWaterPlannedBySectionId.getPlannedTotalWater()){
			return false;
		}
		return true;
	}

}
